<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script>
    var initemsGrid;
    var initemsAction;
    $(function() {
                $('#seqtypeid').combobox({
                    url : '${path }/equipmenttype/eqtype',
                    panelHeight : 'auto',
                    valueField:'id',
                    textField:'equipmenttypename'
                });

                initemsAction = {
                    add : function () {
                        parent.$.modalDialog({
                            title : '添加',
                            width : 500,
                            height : 300,
                            href : '${path }/inspectionitem/addPage',
                            buttons : [ {
                                text : '添加',
                                handler : function() {
                                    parent.$.modalDialog.openner_dataGrid = initemsGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                                    var f = parent.$.modalDialog.handler.find('#initemsAddForm');
                                    f.submit();
                                }
                            } ]
                        });
                    },

                    edit : function () {
                        var rows = $('#box').datagrid('getSelections');
                        if (rows.length == 1) {
                            var index = $('#box').datagrid('getRowIndex', rows[0]);
                            console.log(rows[0]);

                            parent.$.modalDialog({
                                title : '更新',
                                width : 500,
                                height : 400,
                                href : '${path }/inspectionitem/editPage?id='+ rows[0].id,
                                buttons : [ {
                                    text : '更新',
                                    handler : function() {
                                        parent.$.modalDialog.openner_dataGrid = initemsGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                                        var f = parent.$.modalDialog.handler.find('#initemsEditForm');
                                        f.submit();
                                    }
                                } ]
                            });

                        } else {
                            $.messager.alert('警告', '修改必须或只能选择一行！', 'warning');
                        }
                    },
                    remove : function () {
                        var rows = $('#box').datagrid('getSelections');
                        if (rows.length > 0) {
                            $.messager.confirm('确定操作', '您正在要删除所选的记录吗？', function (flag) {
                                if (flag) {
                                    var ids = [];
                                    for (var i = 0; i < rows.length; i ++) {
                                        ids.push(rows[i].id);
                                    }
                                    //console.log(ids.join(','));
                                    $.ajax({
                                        type : 'POST',
                                        url : '/inspectionitem/delete',
                                        data : {
                                            ids : ids.join(','),
                                        },
                                        beforeSend : function () {
                                            $('#box').datagrid('loading');
                                        },
                                        success : function (data) {
                                            if (data) {
                                                $('#box').datagrid('loaded');
                                                $('#box').datagrid('load');
                                                $('#box').datagrid('unselectAll');
                                                $.messager.show({
                                                    title : '提示',
                                                    msg : data + '个设备被删除成功！',
                                                });
                                            }
                                        },
                                    });
                                }
                            });
                        } else {
                            $.messager.alert('提示', '请选择要删除的记录！', 'info');
                        }
                    },
                    search: function () {

                        $('#box').datagrid('load', $.serializeObject($('#searchinitemsForm')));
                    }

                }
            }

    );

    initemsGrid= $('#box').datagrid({
        url : '${path }/inspectionitem/List',
        idField : 'id',
        title : ' 设备列表',
        iconCls : 'icon-search',
        nowrap : true,
        striped: true,
        rownumbers : true,

        frozenColumns : [ [ {
            title : 'id',
            field : 'id',

        } ] ],
        columns : [[
            {
                field : 'eqtypename',
                title : '设备类型',
                sortable : true,
                width :  '10%',

            },

            {
                field : 'inspectionitemname',
                title : '巡查项目',
                sortable : true,
                width :  '10%',
            }


        ]],
        toolbar : '#tb',
        pagination : true,
        pageSize : 10,
        pageList : [10, 20, 30],
        pageNumber : 1,

    });


</script>

<shiro:hasPermission name="+initems+8">
    <div class="easyui-layout" data-options="fit:true">

        <div data-options="region:'center'">
            <table id="box"></table>
            <div id="tb" style="padding:5px;">
                <div style="margin-bottom:5px;">
                    <shiro:hasPermission name="+initems+1">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="initemsAction.add();">添加</a>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="+initems+2">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="initemsAction.edit();">更改</a>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="+initems+4">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="initemsAction.remove();">删除</a>
                    </shiro:hasPermission>


                </div>
                <form id="searchinitemsForm">
                    <table>
                        <tr>
                            <td>设备类型</td><td><select id="seqtypeid" name="eqtypeid" placeholder="请选择设备类型" style="width: 140px; height: 29px;"  ></select></td>

                            <td ><input type="button" value="查询"  onclick="initemsAction.search();"/> <input type="reset" value="重置"/></td>
                        </tr>

                    </table>

                </form>
            </div>
        </div>
    </div>
</shiro:hasPermission>